package com.dick.base.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dick.base.model.BaseUser;
import com.dick.base.parameter.UserParameter;
import com.dick.base.service.UserService;
import com.dick.base.util.BaseResult;
import com.dick.base.util.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("api/users")
public class UserApi {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "分页查询", tags = "用户")
    @GetMapping("page")
    public BaseResult<Page<BaseUser>> userPage(BaseUser user, PageInfo pageInfo) {
        return BaseResult.of(userService.userPage(user, pageInfo));
    }

    @ApiOperation(value = "新增", tags = "用户")
    @PostMapping
    public BaseResult<Void> userAdd(@Valid @RequestBody UserParameter userParameter) {
        userService.userAdd(userParameter);
        return BaseResult.voidResult();
    }

    @ApiOperation(value = "重置密码", tags = "用户")
    @PostMapping("reset")
    public BaseResult<Void> passwordReset(@Valid @RequestBody UserParameter userParameter) {
        userService.passwordReset(userParameter);
        return BaseResult.voidResult();
    }
}
